package chap3_11;

import java.util.Arrays;
import java.util.Scanner;

public class Exer3_11_13 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int[] red = new int[6];//定义红球
        int blue = (int) (Math.random() * (16 - 1) + 1);//定义篮球
        for (int i = 0; i < red.length; i++) {
            red[i] = (int) (Math.random() * (33 - 1) + 1);//取出红球所有组合
        }
        Arrays.sort(red);
        System.out.println("请选择你所购买的蓝球:");
        int chosen_b = input.nextInt();
        while (true) {
            if (chosen_b > 0 && chosen_b <= 16) {//篮球必须输入1-16的数字
                break;
            }
            System.out.println("你选择的号码有误，请重新选择");
        }
        int[] chosen_r = new int[6];

        boolean a = true;//输入红球1-33，超出提示错误重新输入。重复提示重复
        for (int j = 0; j < chosen_r.length; j++) {
            if (a) {
                System.out.println("请选择你所购买的第" + (j + 1) + "颗红球:");
            }
            chosen_r[j] = input.nextInt();
            if (chosen_r[j] < 0 || chosen_r[j] > 33) {
                System.out.println("你选择的号码有误，请重新选择");
                j--;
                continue;
            }
            for (int k = 0; k < j; k++) {
                if (chosen_r[k] == chosen_r[j]) {
                    System.out.println("你输入的第" + (j + 1) + "位重复了，请重新输入");
                    j--;
                    continue;
                }
            }
        }
        Arrays.sort(chosen_r);
        System.out.println("你所购买的双色球红球为：");//输出中奖号码
        for (int l = 0; l < chosen_r.length; l++) {
            System.out.print(chosen_r[l] + ",");
        }
        System.out.println("你所购买的蓝球为" + chosen_b);
        int count = 0;
        for (int m = 1; m < chosen_r.length; m++) {
            if (red[m] == chosen_r[m]) {
                count++;
            }
        }
        System.out.println("中奖号码为：\t蓝球");
        System.out.println(blue);
        System.out.println("红球：");
        for (int n = 0; n < red.length; n++) {
            System.out.print(red[n] + ",");
        }
        if (chosen_b == blue) {
            if (count == 6) {
                System.out.println("恭喜您中了一等奖");
            } else if (count == 5) {
                System.out.println("恭喜您中了三等奖");
            } else if (count == 4) {
                System.out.println("恭喜您中了四等奖");
            } else if (count == 3) {
                System.out.println("恭喜您中了五等奖");
            } else if (count == 2 || count == 1 || count == 0) {
                System.out.println("恭喜您中了六等奖");
            }
        } else {
            if (count == 6) {
                System.out.println("恭喜您中了二等奖");
            } else if (count == 5) {
                System.out.println("恭喜您中了四等奖");
            } else if (count == 4) {
                System.out.println("恭喜您中了五等奖");
            } else if (count == 3 || count == 2 || count == 1 || count == 0) {
                System.out.println("很遗憾，您没中奖");
            }
        }
    }
}











